package easier.app.x;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

public class Security {

    /**
     * 获取字符串的 MD5
     */
    public static String MD5Encode( String str ) {

        try {
            MessageDigest md5 = MessageDigest.getInstance( "MD5" );
            md5.update( str.getBytes( StandardCharsets.UTF_8 ) );
            byte[] messageDigest = md5.digest();
            StringBuilder hexString = new StringBuilder();
            for ( byte b : messageDigest ) {
                hexString.append( String.format( "%02X", b ) );
            }
            return hexString.toString().toLowerCase();
        } catch ( Exception e ) {
            e.printStackTrace();
        }
        return "";
    }
}
